<template>
  <a-config-provider :locale="locale">
    <NuxtLayout>
      <NuxtPage />
    </NuxtLayout>
  </a-config-provider>
</template>

<script setup>
import { getUserAuthInfo } from '@/api/login'
import useCartNum from '@/composables/hooks/useCartNum.js'
import enUS from '@arco-design/web-vue/es/locale/lang/en-us'
import zhCN from '@arco-design/web-vue/es/locale/lang/zh-cn'
const locales = {
  zh: zhCN,
  en: enUS
}

const { locale: langLocale } = useI18nHook()
const userInfo = useUserInfo()
const { isRequest } = useAuth()

const { getCartList, updateCartNumber } = useCartNum()

const locale = computed(() => {
  return locales[langLocale] || zhCN
})

useHead({
  link: [
    { rel: 'shortcut icon', href: '/favicon.ico' },
    { rel: 'apple-touch-icon', href: '/favicon.ico' }
  ]
})

const fetchUserInfo = async () => {
  if (!isRequest.value) return
  await getUserAuthInfo().then((res) => {
    userInfo.value = res.data || {}
  })
}

onBeforeMount(async () => {
  await fetchUserInfo()
  if (isRequest.value) {
  }
})
</script>
